package com.gxa.park.manager.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gxa.park.core.commom.JsonResult;
import com.gxa.park.core.pojo.domain.Inspector;
import com.gxa.park.core.pojo.domain.Park;
import com.gxa.park.core.pojo.domain.Street;
import com.gxa.park.core.pojo.vo.InspectorVO;
import com.gxa.park.manager.service.InspectorStreetService;
import com.gxa.park.manager.service.ManagerService;
import com.gxa.park.manager.service.ParkService;
import com.gxa.park.manager.service.StreetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @date 2022/7/19
 */
@RestController
@RequestMapping("/inspectorStreet")
@Api("巡检员的远程调用相关api")
public class InspectorStreetController {


    @Autowired
    ManagerService managerService;
    @Autowired
    StreetService streetService;
    @Autowired
    ParkService parkService;

    @ApiOperation(value = "通过泊位编号查询巡检员信息",produces = "query")
    @PostMapping("/selectedInspectorByPake")
    public Map selectedInspectorByPake( @RequestParam(value = "泊位编号")String number){
        LambdaQueryWrapper<Park> lambda=Wrappers.lambdaQuery(Park.class);
        lambda.eq(Park::getPaNumber,number);
        Park one = parkService.getOne(lambda);
        Integer paStreet = one.getPaStreet();

        LambdaQueryWrapper<Inspector> inspectorLambda = Wrappers.lambdaQuery(Inspector.class);
        inspectorLambda.eq(Inspector::getInStreet,paStreet);
        Inspector inspector = managerService.getOne(inspectorLambda);

        JsonResult jsonResult =new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(inspector);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "通过泊位编号查询街道信息",produces = "query")
    @PostMapping("/selectedStreetByPake")
    public Map selectedStreetByPake( @RequestParam(value = "泊位编号")String number) {
        LambdaQueryWrapper<Park> lambda=Wrappers.lambdaQuery(Park.class);
        lambda.eq(Park::getPaNumber,number);
        Park one = parkService.getOne(lambda);
        Integer paStreet = one.getPaStreet();

        LambdaQueryWrapper<Street> streetLambdaQueryWrapper = Wrappers.lambdaQuery(Street.class);
        streetLambdaQueryWrapper.eq(Street::getStrId,paStreet);
        Street one1 = streetService.getOne(streetLambdaQueryWrapper);

        JsonResult jsonResult =new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(one1);
        return jsonResult.getMap();
    }
}
